package com.woniuxy.movie.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.movie.commons.web.util.StateData;
import com.woniuxy.movie.product.dao.ProductTicketMapper;
import com.woniuxy.movie.product.form.ticket.TicketSaledForm;
import com.woniuxy.movie.product.model.ProductTicket;
import com.woniuxy.movie.product.service.ProductTicketService;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * <p>
 * 电影票详情表 服务实现类
 * </p>
 *
 * @author 刘存益
 * @since 2023年11月17日
 */
@Service
public class ProductTicketServiceImpl extends ServiceImpl<ProductTicketMapper, ProductTicket> implements ProductTicketService {

    /**
     * 通过多个ID修改票务状态为锁定状态
     * @param ids
     * @return
     */
    @Override
    public Integer saveLock(Set<Integer> ids) {
        ProductTicket pt = new ProductTicket();
        pt.setTicketState(StateData.TICKET_STATE_LOCKED);
        Integer cont = this.baseMapper.update(pt,new UpdateWrapper<ProductTicket>().in("ticket_id",ids));
        return cont;
    }

    /**
     * 通过多个ID修改票务状态为已售状态以及其它信息
     * @param form
     * @return
     */
    @Override
    public Integer saveSaled(TicketSaledForm form) {
        ProductTicket pt = new ProductTicket();
        pt.setTicketState(StateData.TICKET_STATE_SALED);
        pt.setTicketUser(form.getTicketUser());
        pt.setTicketTime(form.getTicketTime());
        Integer cont = this.baseMapper.update(pt,new UpdateWrapper<ProductTicket>().in("ticket_id",form.getIds()));
        return cont;
    }

    /**
     * 通过多个ID修改票务状态为正常待售状态
     * @param ids
     * @return
     */
    @Override
    public Integer saveNormal(Set<Integer> ids) {
        ProductTicket pt = new ProductTicket();
        pt.setTicketState(StateData.TICKET_STATE_NORMAL);
        Integer cont = this.baseMapper.update(pt,new UpdateWrapper<ProductTicket>().in("ticket_id",ids));
        return cont;
    }

}
